
import { createRouter, createWebHashHistory } from 'vue-router'
import layout from '@/layout/index.vue'
import index from '@/views/home/index'
import custom from '@/views/custom/index'


import { routes as userRoutes } from './user/index'
import { routes as activityRoutes } from './activity/index'

const router = createRouter({
  history: createWebHashHistory('/pc/'),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: layout,
      redirect: { name: 'index' },
      children: [
        // 首页
        {
          path: '/index',
          name: 'index',
          component: index,
          meta: {
            logoText: '',
            searchVisible: false
          }
        },
        // 自定义页面
        {
          path: '/custom',
          name: 'custom',
          component: custom,
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 店铺主页
        {
          path: '/store',
          name: 'store',
          component: () => import('@/views/store/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 评价
        {
          path: '/evaluate',
          name: 'evaluate',
          component: () => import('@/views/evaluate/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 购物车
        {
          path: '/shopping-trolley',
          name: 'shoppingTrolley',
          component: () => import('@/views/shopping-trolley/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 订单详情
        {
          path: '/orderDetail',
          name: 'orderDetail',
          component: () => import('@/views/orderDetail/index'),
          meta: {
            logoText: '',
            searchVisible: false
          }
        },
        // 商品详情
        {
          path: '/productDetail',
          name: 'productDetail',
          component: () => import('@/views/product/productDetail'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 下单页面
        {
          path: '/placeOrder',
          name: 'placeOrder',
          component: () => import('@/views/placeOrder/index'),
          meta: {
            logoText: '收银台',
            searchVisible: true
          }
        },
        // 支付结果页面——支付有礼
        {
          path: '/orderResult',
          component: () => import('@/views/placeOrder/orderResult.vue'),
          meta: {
            searchVisible: true
          }
        },
        // 售后
        {
          path: '/afterSale',
          name: 'afterSale',
          component: () => import('@/views/afterSale/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 评价详情
        {
          path: '/evaluateDetail',
          name: 'evaluateDetail',
          component: () => import('@/views/evaluateDetail/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 追评
        {
          path: '/addEvaluate',
          name: 'addEvaluate',
          component: () => import('@/views/addEvaluate/index'),
          meta: {
            logoText: '',
            searchVisible: true
          }
        },
        // 个人中心
        ...userRoutes,
        // 活动页面
        ...activityRoutes,
      ]
    }
  ]
})


router.beforeEach((to, from, next) => {
  // cookie没有值就跳到登陆页
  // let area = sessionStorage.getItem('area')
  // if (area === null && to.name !== 'login' && to.name !== 'overview') {
  //   // Vue.prototype.$message.error('用户未登陆')
  //   next('/login')
  // } else {
  next()
  // }
})

export default router
